/********************************************************************************
* @File name: main.c
* @Author: abyss
* @Version: 1.0
* @Date: 2023-8-04
* @Description: 用于arm得立即数与机器码的转换
********************************************************************************/
#include "stdio.h"

/********************************************************
* Function name ：ror_cyc
* Description   : 循环右移
* @imm          ：需要循环右移的数据
* @cyc          ：右移的次数
**********************************************************/
unsigned int ror_cyc(unsigned int imm,int cyc)
{
    imm = imm|0x80000000;
    for(int conter=0;conter<cyc;conter++){
        imm = imm>>1|imm<32;
    }
    return imm;
}

/********************************************************
* Function name ：ror_cyc
* Description   : 循环右移
* @iimm3a       ：机器码的iimm3a
* @abcdefgh     ：机器码中的abcdefgh
**********************************************************/
unsigned int immediate_conversion(unsigned char iimm3a,unsigned char abcdefgh)
{
    unsigned int immediate;
    immediate = abcdefgh;
    if((iimm3a==0)||(iimm3a==0b00001))
    {
        immediate = abcdefgh;
    }
    else if((iimm3a==0b00010)||(iimm3a==0b00011))
    {
        immediate = immediate<<16|immediate;
    }
    else if((iimm3a==0b00100)||(iimm3a==0b00101))
    {
        immediate = immediate<<24|immediate<<8;
    }
    else if((iimm3a==0b00110)||(iimm3a==0b00111))
    {
        immediate = immediate<<24|immediate<<16|immediate<<8|immediate;
    }
    else
    {
        immediate = immediate<<24;
        immediate = ror_cyc(immediate,iimm3a-0b01000);
    }
    return immediate;
}

/********************************************************
* Function name ：main
* Description   ：main
**********************************************************/
int main()
{
    printf("int 存储大小 : %lu \n", sizeof(int));
    printf("char 存储大小 : %lu \n", sizeof(char));
    if(sizeof(int)!=4)return -1;

    unsigned int immediate;
    unsigned char iimm3a = 0b11111;
    unsigned char abcdefgh = 0xff;

    // printf("%x\n",iimm3a);
    // if((iimm3a&0x01)==0)
    // {
    //     abcdefgh=0x55;
    // }
    // else 
    // {
    //     abcdefgh = 0xaa;
    // }
    
    // printf("abcdefgh:0x%X\n",abcdefgh);

    immediate = immediate_conversion(iimm3a,abcdefgh);
    printf("immediate:0x%X\n",immediate);
    return 0;
}



